﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Imports Darwen.Windows.Forms.Controls.Docking
Imports Darwen.Windows.Forms.Controls.TabbedDocuments

Namespace kotorito

    Public Class ctlMain
        Inherits Darwen.Windows.Forms.Controls.Docking.DockingManagerControl

        Public rightPanel As IDockingPanel
        Public BotommPanel As IDockingPanel
        Public LeftPanel As IDockingPanel

        Private Sub ctlMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            InitializeComponent()
            rightPanel = Me.Panels(DockingType.Right).InsertPanel(0)
            BotommPanel = Me.Panels(DockingType.Bottom).InsertPanel(0)
            LeftPanel = Me.Panels(DockingType.Left).InsertPanel(0)
            General.Settings = New clsSettings

            General.Control_Explorer = New ctlExplorer
            General.Control_Controls = New ctlControls
            General.Control_Console = New ctlConsole
            General.Control_Properties = New ctlProperties
            General.Control_Eventos = New ctlEventos
            General.Control_Debug = New ctlDebug
            
            addpanel ("explorer")
            addpanel ("properties")
            addpanel ("controls")
            addpanel ("events")
            addpanel ("debug")
            addpanel ("console")
            
            'Dim dockingControl1 As IDockingControl = LeftPanel.DockedControls.Add(Object_Language.Lang_Text("Explorer"), General.Control_Explorer)
            'Dim dockingControl2 As IDockingControl = LeftPanel.DockedControls.Add(Object_Language.Lang_Text("Controls"), General.Control_Controls)
            'Dim dockingControl3 As IDockingControl = BotommPanel.DockedControls.Add(Object_Language.Lang_Text("Console"), General.Control_Console)
            'Dim dockingControl4 As IDockingControl = rightPanel.DockedControls.Add(Object_Language.Lang_Text("Properties"), General.Control_Properties)
            'Dim dockingControl5 As IDockingControl = rightPanel.DockedControls.Add(Object_Language.Lang_Text("Events"), General.Control_Eventos)
            'Dim dockingControl6 As IDockingControl = BotommPanel.DockedControls.Add(Object_Language.Lang_Text("Debug"), General.Control_Debug)
            'dockingControl3.AutoHide = True
            General.Control_Console.CheckForIllegalCrossThreadCalls = False
            General.Control_Menu.CheckForIllegalCrossThreadCalls = False

        End Sub
        
        Public Sub addpanel(ByVal panel As String)
        	Select Case panel
        		Case "explorer"
        			Dim dockingControl1 As IDockingControl = LeftPanel.DockedControls.Add(Object_Language.Lang_Text("Explorer"), General.Control_Explorer)
        			
        		Case "controls"
        			Dim dockingControl2 As IDockingControl = LeftPanel.DockedControls.Add(Object_Language.Lang_Text("Controls"), General.Control_Controls)
        			
        		Case "properties"
        			Dim dockingControl4 As IDockingControl = rightPanel.DockedControls.Add(Object_Language.Lang_Text("Properties"), General.Control_Properties)
        			
        		Case "console"
        			Dim dockingControl3 As IDockingControl = BotommPanel.DockedControls.Add(Object_Language.Lang_Text("Console"), General.Control_Console)
        			
        		Case "events"
        			Dim dockingControl5 As IDockingControl = rightPanel.DockedControls.Add(Object_Language.Lang_Text("Events"), General.Control_Eventos)
        			
        		Case "debug"
        			Dim dockingControl6 As IDockingControl = BotommPanel.DockedControls.Add(Object_Language.Lang_Text("Debug"), General.Control_Debug)
        			
        	End Select
        End Sub
                
        Friend WithEvents tabContainer As Darwen.Windows.Forms.Controls.TabbedDocuments.TabbedDocumentControl

        Private Sub InitializeComponent()
            Dim ToolStripProfessionalRenderer1 As System.Windows.Forms.ToolStripProfessionalRenderer = New System.Windows.Forms.ToolStripProfessionalRenderer
            Me.tabContainer = New Darwen.Windows.Forms.Controls.TabbedDocuments.TabbedDocumentControl
            Me.SuspendLayout()
            '
            'tabContainer
            '
            Me.tabContainer.BackColor = System.Drawing.SystemColors.AppWorkspace
            Me.tabContainer.Dock = System.Windows.Forms.DockStyle.Fill
            Me.tabContainer.Location = New System.Drawing.Point(30, 24)
            Me.tabContainer.Name = "tabContainer"
            ToolStripProfessionalRenderer1.RoundedEdges = True
            Me.tabContainer.Renderer = ToolStripProfessionalRenderer1
            Me.tabContainer.Size = New System.Drawing.Size(751, 488)
            Me.tabContainer.TabIndex = 15
            '
            'ctlMain
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.Controls.Add(Me.tabContainer)
            Me.Name = "ctlMain"
            Me.Controls.SetChildIndex(Me.tabContainer, 0)
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub

        Private Function FileIsLoaded(ByVal Path As String) As Boolean
            FileIsLoaded = False
            For i = 0 To tabContainer.Items.Count - 1
                'If tabContainer.Items(i).Name = "ctlEditor" Then
                Dim Editor As Object = tabContainer.Items(i)
                If Editor.ToString = "BeeWit.ctlEditor" Then
                    If Editor.Path.ToString.ToUpper = Path.ToString.ToUpper Then
                        tabContainer.Items(i).Focus()
                        tabContainer.Items(i).Select()
                        tabContainer.SelectedControl = Editor
                        FileIsLoaded = True
                    End If
                End If
                'End If
            Next
        End Function

        Public Sub AddEditor(ByVal pathFile As String, ByRef Node As clsNode)
            If Not FileIsLoaded(pathFile) Then
                Dim Editor As New BeeWit.ctlEditor
                Dim Title As String = pathFile.Substring(pathFile.LastIndexOf("\") + 1)
                Editor.Node = Node
                Editor.Path = pathFile
                tabContainer.Items.Add(Title, Editor)
                tabContainer.Items(tabContainer.Items.Count - 1).Name = Title
                tabContainer.SelectedControl = Editor
                Editor.ShowEditor()
                General.BeeWitFocused = True
            End If
        End Sub
                
        Public Sub AddBegin()
            'For i = 0 To tabContainer.Items.Count - 1
            '    If tabContainer.Items(i).Name = "ctlBegin" Then
            '        Dim TabyBegin As ctlBegin = tabContainer.Items(i)
            '        TabyBegin.Focus()
            '        TabyBegin.Select()
            '        tabContainer.SelectedControl = TabyBegin
            '        Exit Sub
            '    End If
            'Next
            Dim Welcome As New ctlBegin
            tabContainer.Items.Add(Object_Language.Lang_Text("Begin"), Welcome)
            tabContainer.Items(tabContainer.Items.Count - 1).Name = Object_Language.Lang_Text("Begin")
        End Sub

        Public Sub AddControlToDesigner(ByVal ClassName As String)
            If tabContainer.SelectedControl.ToString = "BeeWit.ctlEditor" Then
                Dim Editor As ctlEditor = tabContainer.SelectedControl
                Editor.AddControl(ClassName)
            End If
        End Sub

        Public Sub Save()
            If tabContainer.SelectedControl.ToString = "BeeWit.ctlEditor" Then
                Dim Editor As ctlEditor = tabContainer.SelectedControl
                Editor.Save()
                Control_Console.AddMessages("Saved! " & Editor.Name & ". ", ctlConsole.enumTypeMessages.isINFORMATION)
            End If
        End Sub

        Public Sub Reload()
            If tabContainer.SelectedControl.ToString = "BeeWit.ctlEditor" Then
                Dim Editor As ctlEditor = tabContainer.SelectedControl
                MsgBox("is not implemented")
            End If
        End Sub

        Public Sub SaveAll()
            Control_Console.AddMessages("Saving All--->", ctlConsole.enumTypeMessages.isINFORMATION)
            For i = 0 To tabContainer.Items.Count - 1
                If tabContainer.Items(i).ToString = "BeeWit.ctlEditor" Then
                    Dim Editor As ctlEditor = tabContainer.Items(i)
                    Editor.Save()
                    Control_Console.AddMessages("Saved! " & Editor.Name & ". ", ctlConsole.enumTypeMessages.isINFORMATION)
                End If
            Next
            Control_Console.AddMessages("<--- All Saved.", ctlConsole.enumTypeMessages.isINFORMATION)
        End Sub

        Public Function ActualEditor() As ctlEditor
            If Not tabContainer.SelectedControl Is Nothing Then
                If tabContainer.SelectedControl.ToString = "BeeWit.ctlEditor" Then
                    Dim Editor As ctlEditor = tabContainer.SelectedControl
                    Return Editor
                End If
            End If
            Return Nothing
        End Function

        Private Sub tabContainer_SelectedControlChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabContainer.SelectedControlChanged
            Try
                Dim Editor As ctlEditor = General.Control_Main.ActualEditor
                If Not Editor Is Nothing Then
                    Editor.HTML.ValidateAttributes()
                End If
            Catch ex As Exception

            End Try
        End Sub

    End Class

End Namespace

